package com.wx.service.impl;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.wx.dao.SysWxTokenMapper;
import com.wx.entity.SysWxToken;
import com.wx.entity.SysWxTokenExample;
import com.wx.entity.SysWxuser;
import com.wx.service.SysWxTokenService;
import com.wx.service.TokenService;
import com.zyht.redis.service.RedisService;
import com.zyht.wechat.AccessTokenVisitor;

@Service("SysWxTokenService")
public class SysWxTokenServiceImpl implements SysWxTokenService {
	@Resource
	private SysWxTokenMapper wxTokenMapper;
	
	@Resource
	private AccessTokenVisitor accessTokenVistor;


	@Resource
	private RedisService redisService;

	@Resource
	private TokenService tokenService;

	@Override
	public int insert(SysWxToken token) {
		return wxTokenMapper.insert(token);
	}

	@Override
	public int insertSelective(SysWxToken token) {
		return wxTokenMapper.insert(token);
	}

	@Override
	public List<SysWxToken> selectByExample(SysWxTokenExample example) {
		return wxTokenMapper.selectByExample(example);
	}

	@Override
	public SysWxToken selectByPrimaryKey(Integer id) {
		return wxTokenMapper.selectByPrimaryKey(id);
	}

	@Override
	public int countByExample(SysWxTokenExample example) {
		return wxTokenMapper.countByExample(example);
	}

	@Override
	public int updateByExample(SysWxToken record, SysWxTokenExample example) {
		return wxTokenMapper.updateByExample(record, example);
	}

	@Override
	public int updateByPrimaryKey(SysWxToken record) {
		return wxTokenMapper.updateByPrimaryKey(record);
	}

	@Override
	public int deleteByPrimaryKey(Integer id) {
		return wxTokenMapper.deleteByPrimaryKey(id);
	}

	@Override
	public int deleteByExample(SysWxTokenExample example) {
		return wxTokenMapper.deleteByExample(example);
	}

	
	/**
	 * 此方法封装了下面的方法
	 */
	@Override
	public String getAccessToken(SysWxuser sysWxuser) {
		return getAccessToken(sysWxuser.getWxid(), sysWxuser.getAppid(), sysWxuser.getAppsecretd());
	}

	/**
	 * 
	 * 授权token暂时未测试 , wxtoken可用 @Title: getAccessToken @Description:
	 * 获取accessToken @param @param uid @param @param wxid @param @param
	 * appId @param @param appSecret @param @return 设定文件 @return String
	 * 返回类型 @throws
	 */
	@Override
	public String getAccessToken(String wxid, String appId, String appSecret) {
		return accessTokenVistor.getTokenSequence(wxid, appId, appSecret);
	}
}